package me.cjj.android.assignment.model

class LinearQuestion(private val k: Int, private val d: Int) : IQuestion {

    override fun getQuestionText(): String {
        val kText = k.toQuestionText(true, "x")
        val dText = d.toQuestionText()
        return "\\($kText$dText=0\\)"
    }

    override fun getAnswerCount(): Int {
        return 1
    }

    override fun getAnswerText(): String {
        return getAnswer().toString()
    }

    override fun judge(vararg answers: Float): Boolean {
        val correct: Float = getAnswer()
        return (Math.round(correct * 100) / 100.toFloat()) == answers[0]
    }

    private fun getAnswer() = -d.toFloat() / k.toFloat()

}